// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause

#ifndef FORTUNETHREAD_H
#define FORTUNETHREAD_H

#include <QThread>
#include <QTcpSocket>



//! [0]
class FortuneThread : public QThread
{
    Q_OBJECT
    //


public:
    FortuneThread(int socketDescriptor, const QString &fortune, const QString &name, QObject *parent);
    ~FortuneThread();

    void run() override;


    enum Sta_server {
        WaitPwd,            //等待密码
        WaitAskData,        //等待索要数据
        SendingData,        //发送数据中
        WaitAckData,        //等待数据确认包
    };
    Q_ENUM(Sta_server)

signals:
    void error(QTcpSocket::SocketError socketError);
    void error_str(QString err);        //感觉像是临时信号。
    void error_to_gui(QString err);     //发给GUI的信号。


private:
    int socketDescriptor;
    QString text;
    qint64 tot;             //接收到的数据总字节数。
    QTcpSocket tcpSocket;
    QString bin_file_name_path;
    QString bin_file_name;



private slots:
    void readFortune();
    void DataWritten(qint64 bytes);
    void disp_err(QString err);
};
//! [0]

#endif
